package com.event.usc.background;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * Application Lifecycle Listener implementation class testListener
 *
 */
//@WebListener
public class CrawlerListener implements ServletContextListener {

    /**
     * Default constructor. 
     */
	private Crawler crawler = null;
    public CrawlerListener() {
    	super();
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent arg0) {
    	if ((crawler== null) || (!crawler.isAlive())) {
            crawler = new Crawler();
            crawler.start();
        }
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0) {
    	try {
            crawler.interrupt();
        } catch (Exception ex) {
        	//ignore
        }
    }
	
}
